home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / GRAPTIES / SD204.LZH / GETLNE.PAS < prev    next >
Pascal/Delphi Source File  |  1980-01-01  |  5KB  |  131 lines

  1. UNIT GETLNE;
  2.  
  3. INTERFACE
  4.  USES IOSTUFF,KEY2,CRT;
  5.  
  6.  FUNCTION GetStr(X,Y,Len:Integer;Default:AnyStr) : AnyStr;
  7.  
  8. IMPLEMENTATION
  9.  
  10. CONST
  11.   LeftArrow  = #75;         { Keys used in editing string }
  12.   RightArrow = #77;
  13.   InsertKey  = #82;
  14.   DeleteKey  = #83;
  15.   EnterKey   = #13;
  16.   EscKey     = #27;
  17.   BackSpKey  = #8;
  18.   CtrlBackSp = #127;
  19.   HomeKey    = #71;
  20.   EndKey     = #79;
  21.  
  22. VAR
  23.   InsToggle : Boolean;     { Insert key toggle switch }
  24.   Virgin    : Boolean;     { Used for edit versus enter-new decision }
  25.  
  26. {======================================================================}
  27. FUNCTION GetStr(X,Y,Len:Integer;Default:AnyStr) : AnyStr;
  28. VAR
  29.    ExitGetStr          : Boolean;  { Exit switch }
  30.    TCh                 : Char;     { Current keystroke }
  31.    XG,II               : Integer;  { Remember starting X position }
  32.    TempStr             : AnyStr;   { Temporary string for editing }
  33.  { FunctKey            : Boolean;    True if keystroke was function key }
  34.                                    { FunctKey is defined in Key }
  35. BEGIN
  36.    ExitGetStr := False;   { Set exit switch false }
  37.    XG := X;
  38.    X := X+Length(Default);            { Set X location of cursor }
  39.    FillChar(TempStr,Sizeof(TempStr),' ');  { Fill TempStr with Blanks }
  40.    Tempstr[0] := Chr(Len);
  41.    WriteSt(TempStr,XG,Y);              { Write blanks on screen }
  42.    InsToggle := False;                 { Start with insert off }
  43.    ShowCursor;                         { Make sure cursor is visible }
  44.    LineCursor;                         { Make cursor small }
  45.    WriteSt(Default,XG,Y);              { Write default on screen }
  46.    Virgin := true;                     { Assume default will not be edited }
  47. Repeat
  48.      If X > XG+Len-1 then Begin        { Increment cursor location }
  49.        X := XG+Len-1;
  50.        Beep;
  51.      End;
  52.      If X < XG then Begin              { Don't let cursor get out of field }
  53.        X := XG;
  54.        Beep;
  55.      End;
  56.  
  57.       GoToXY(X,Y);                    { Position cursor }
  58.  
  59.       If InsToggle then Bigcursor else Linecursor;   { Make cursor big }
  60.  
  61.       TCh := NextKey;                    { Read a keystroke }
  62.  
  63.   If FunctKey then case TCh of       { Handle function keys here }
  64.       LeftArrow : X := X - 1;      { Decrement cursor location }
  65.       RightArrow: X := X + 1;      { Increment cursor location }
  66.       InsertKey : Begin              { Toggle insert switch on/off}
  67.                    InsToggle := not InsToggle;
  68.                    If InsToggle then Bigcursor  {block cursor - ins off}
  69.                    Else Linecursor;             {line cursor - ins on}
  70.                   End;
  71.       DeleteKey : Begin             {delete - destruct Char at cursor}
  72.                    TempStr:= ReadFromScr(X+1,Y,XG+Len-X-1);
  73.                    WriteSt(TempStr,X,Y);
  74.                    Write(' ');
  75.                   End;
  76.       HomeKey   : X := XG;          { Cursor to begining of string }
  77.       EndKey    : X := XG+Len-1;    { Cursor to end of string }
  78.  
  79.    End;  {Function key true}
  80.  
  81.   If not FunctKey then case TCh of    {  Handle non function keys }
  82.       #28..#126,
  83.       #128..#255 : Begin              { Regular everyday Characters}
  84.                     If Virgin then Begin   { If virgin then delete default }
  85.                        FillChar(TempStr,Sizeof(TempStr),' ');
  86.                        Tempstr[0] := Chr(Len);
  87.                        WriteSt(TempStr,XG,Y);
  88.                        X := XG;
  89.                        GoToXY(X,Y);
  90.                      End;
  91.                     If InsToggle then Begin  { If insert then push characters }
  92.                       TempStr := ReadFromScr(X,Y,XG+Len-X-1);
  93.                       WriteSt(TempStr,X+1,Y);
  94.                       GoToXY(X,Y);
  95.                      End;
  96.                     Write(TCh);        { Finally write the character on screen }
  97.                     X := X+1;
  98.                   End;
  99.        EnterKey : Begin                   { Get set to exit }
  100.                    ExitGetStr := true;
  101.                   End;
  102.        EscKey   : Begin                   { Exit now with a nul string }
  103.                    GetStr := '';
  104.                    Exit;
  105.                   End;
  106.        BackSpKey :Begin                  { Destruct Char to left }
  107.                    If X > XG then Begin
  108.                      TempStr := ReadFromScr(X,Y,XG+Len-X);
  109.                      WriteSt(TempStr,X-1,Y);
  110.                      Write(' ');
  111.                    End;
  112.                      X := X-1;
  113.                   End;
  114.        CtrlBackSp :Begin                { Delete entire string }
  115.                      FillChar(TempStr,Sizeof(TempStr),' ');
  116.                      Tempstr[0] := Chr(Len);
  117.                      WriteSt(TempStr,XG,Y);
  118.                      X := XG;
  119.                    End;
  120.  
  121.    End; { FunctKey false}
  122.  Virgin := false;        { Set virgin false if any editing key hit }
  123. Until ExitGetStr;
  124.  
  125.    Linecursor;                         { Reset the cursor }
  126.    GetStr := ReadFromScr(XG,Y,Len);   { Read the edited string from screen }
  127.  
  128.  
  129. END;
  130.  
  131. END.  {UNIT}